package zondy.yapi.extProject.send;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;

import java.util.List;

public class DingTalkMessageSend implements MessageSend {

    @Override
    public void sendMessage(List<String> subjectList, String message) throws Exception {
        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=c4248dab1303db15ff67e44efb89159490d716c83636b7dbd786e6c36ddf5987");
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        // 通知信息类型
        request.setMsgtype("text");
        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
        // 通知内容
        text.setContent(message);
        request.setText(text);
        OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
        // TODO 通过subjectList，发送给指定负责项目的成员
        // 目前@所有人
        at.setIsAtAll(true);
        request.setAt(at);

        OapiRobotSendResponse response = client.execute(request);
        System.out.println(response.getBody());
    }

}
